$(document).ready( function() {
	dataSource = [];
	
});

function visualisation()
{
	var datedebut = $("#inpt_dateDebut").val();
	var dateFin = $("#inpt_dateFin").val();
	report(datedebut, dateFin);
	
	$("#div_chart").show();
	$("#span_dateDebut").html(datedebut);
	$("#span_dateFin").html(dateFin);

	
}


function report(dateDebut,dateFin)
{ 
		
		var request = 'dateDebut=' + dateDebut + "&dateFin=" + dateFin;
		
		$.ajax({  type: "POST", url: "reporting/index",  data: request,
			
		    	  success: function(response){
		        
				    	var CData = [];
				    	for(var i=0; i < response.length;i++)
				    	{
				    		var data = { value : response[i].value, date : response[i].date};
				    		CData.push(data);
				    	}
				    	
			    	
				    	dataSource = new Array(CData.length); 
				    	dataSource  = CData;
				    	
				    	refreshGraph();
						 
			      },
			      error: function(e){
			    	  alert('Error: ' + e.statusText);
			      }
		});
}

//Fin Appel Ajax

function createChart() {
    $("#myChart").kendoChart({
        title: {
            text: "Courbe d'index"
        },
        dataSource: {
            data: stats
        },
        series: [{
            type: "line",
            aggregate: "avg",
            field: "value",
            categoryField: "date"
        }],
        categoryAxis: {
            baseUnit: "days"
        }
    });
}


function refreshGraph()
{

     $(document).ready(createChart);
     $(document).bind("kendo:skinChange", createChart);
	 
}